//  Copyright (c) 2011 M.A. (Thijs) van den Berg, http://sitmo.com/
//
//  Use, modification and distribution are subject to the MIT Software License. 
// (See accompanying file LICENSE.txt or copy at http://www.bmlib.org/LICENSE.txt)

#ifndef BMLIB_GBM_PROCESS
#define BMLIB_GBM_PROCESS

// 
// SDE: dXt = Xt mu + sigma dWt
//       X0 = x

#include <cmath>
#include <boost/math/distributions/normal.hpp>
using namespace boost::math;

#include <bmlib/at_fixed_time.hpp>

namespace bmlib{ 

template <class RealType = double>
class gbm_process
{
public:
    typedef RealType value_type;
    
    gbm_process(RealType x = 0, RealType mu = 0, RealType sigma = 1)
        : m_x(x), m_mu(mu), m_sigma(sigma)
    {
        // todo check sigma
    }
    
    RealType x() const
    {
        return m_x;
    }

    RealType mu() const
    {
        return m_mu;
    }
    
    RealType sigma() const
    {
        return m_sigma;
    }
    
private:
    //
    // Data members:
    //
    RealType m_x;
    RealType m_mu;
    RealType m_sigma;
}; // class gbm_process

template <class RealType>
inline RealType cdf(const at_fixed_time< gbm_process<RealType> >& distribution, RealType level)
{
    RealType x = distribution.process().x();
    RealType mu = distribution.process().mu();
    RealType sigma = distribution.process().sigma();
    RealType t = distribution.t();
    
    RealType mean = mu*t;
    RealType sd = sigma*sqrt(t);

    return boost::math::cdf( 
        boost::math::normal_distribution<double>(mean, sigma),
        log(level/x)
        );
}

} // namespaces bmlib
#endif